<template>
	<view>
		<uni-list>
			<uni-list-item v-for="item of list" :key="item.id" :title="`${item.fundName}(${item.fundCode})`" :note="`投资时间 ${item.investTime}`" :right-text="`投资金额 ${item.investAmount}`" link :to="`/pages/my/investDetail?id=${item.id}`"></uni-list-item>
		</uni-list>
		<uni-load-more :status="status" :contentText="CONTENT_TEXT" @clickLoadMore="loadMore"></uni-load-more>
	</view>
</template>

<script setup>
import { onMounted, ref } from 'vue';
import { fetchUserInvestInfoList } from '../../api/adventure.js'
import { CONTENT_TEXT, PAGE_SIZE } from '../../utils/constant.js'

const status = ref('more')
const currentPage = ref(0)
const list = ref([])

const loadData = async () => {
	const { success, data } = await fetchUserInvestInfoList({
		pageNum: currentPage.value,
		pageSize: PAGE_SIZE
	})
	return data
}

const loadMore = async () => {
	if (status.value !== 'more') return
	currentPage.value += 1
	status.value = 'loading'
	const data = await loadData()
	if (data.length > 0) {
		list.value = [...list.value, ...data]
		status.value = 'more'
	} else {
		status.value = 'noMore'
	}
	
}

const onItemClick = (id) => {
	// uni.navigateTo({
	// 	url: `/pages/home/prizeDetail?id=${id}`
	// })
}

onMounted(() => {
	loadMore()
})
</script>

<style>

</style>
